#include "Quimera_protocol_v1.cpp"

int main(int argc, char **argv){
    
    unsigned char domain;
    unsigned short interval;
    unsigned int beacon_number;
    struct sockaddr_in iprserv;
    pthread_t init_contact; 
    
    bzero((char *) &iprserv, sizeof(iprserv));
    domain=unsigned(char(atoi(argv[2])));
    iprserv.sin_addr.s_addr=inet_addr(argv[3]);
    interval = atoi(argv[4]);
    beacon_number = atoi(argv[5]);
    
    
    Quimera_client QC(domain,iprserv,interval,beacon_number);
  
    if(QC.Connect()==EXIT_SUCCESS and QC.quality_control==true){
       
        if(pthread_create(&init_contact,NULL, &Quimera_client::Keep_intouch,QC.p_this)==0){
            if(QC.online){
            std::cout<<"Estoy listo\n";
            return(QC.Listen());
            }
        }
        else{
            bzero((char *) &QC.log_msg, sizeof(QC.log_msg));
            QC.log_msg.id_message=LOG_QUEUE_ERR_TOUCH;
            msgsnd(QC.l_queue_id, (struct msgbuf *)&QC.log_msg,
            sizeof(QC.log_msg)-sizeof(long),IPC_NOWAIT);
            return (EXIT_FAILURE);
        }
    }
    return(EXIT_FAILURE);
}
